﻿using MCUPackage.Utils;
using System;
using System.ComponentModel;

namespace SxPackages.STC32G.Models
{
	class PWMxOptions<T> : PWMOptionBase where T : IComparable
	{
		private T mPins = default(T);

		[DisplayName("使用引脚"),
		Description("设置本通道使用的引脚"),
		DefaultValue(0)]
		public T Pins
		{
			get => mPins;
			set
			{
				if (!value.Equals(mPins))
				{
					if (!SwitchPins(value, mPins))
					{
						return;
					}

					mPins = value;
				}
			}
		}

		public PWMxOptions(STC32GQFP64 aParent) : base(aParent)
		{
			this.mUsePins = TemplateHelper.GetPins(this.Pins);
		}
	}

	class PWM1Options : PWMxOptions<PWM1Pins>
	{
		public PWM1Options(STC32GQFP64 aParent) : base(aParent)
		{
			this.Channel = 1;
		}
	}

	class PWM2Options : PWMxOptions<PWM2Pins>
	{
		public PWM2Options(STC32GQFP64 aParent) : base(aParent)
		{
			this.Channel = 2;
		}
	}

	class PWM3Options : PWMxOptions<PWM3Pins>
	{
		public PWM3Options(STC32GQFP64 aParent) : base(aParent)
		{
			this.Channel = 3;
		}
	}

	class PWM4Options : PWMxOptions<PWM4Pins>
	{
		public PWM4Options(STC32GQFP64 aParent) : base(aParent)
		{
			this.Channel = 4;
		}
	}

	class PWM5Options : PWMxOptions<PWM5Pins>
	{
		[Browsable(false)]
		public override Boolean EnableN => false;

		public PWM5Options(STC32GQFP64 aParent) : base(aParent)
		{
			this.Channel = 5;
		}
	}

	class PWM6Options : PWMxOptions<PWM6Pins>
	{
		[Browsable(false)]
		public override Boolean EnableN => false;

		public PWM6Options(STC32GQFP64 aParent) : base(aParent)
		{
			this.Channel = 6;
		}
	}

	class PWM7Options : PWMxOptions<PWM7Pins>
	{
		[Browsable(false)]
		public override Boolean EnableN => false;

		public PWM7Options(STC32GQFP64 aParent) : base(aParent)
		{
			this.Channel = 7;
		}
	}

	class PWM8Options : PWMxOptions<PWM8Pins>
	{
		[Browsable(false)]
		public override Boolean EnableN => false;

		public PWM8Options(STC32GQFP64 aParent) : base(aParent)
		{
			this.Channel = 8;
		}
	}
}
